<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!--<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
    <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
    <button class="layui-btn" data-type="isAll">验证是否全选</button>
</div>-->
<!--<h3 style="margin-top: -10px; margin-left:-10px;">检测入库</h3>-->
<div class="demoTableSaleOrder">
    <div class="layui-inline" style="margin-left:0px">销售单号：</div>
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="saleNumSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入销售单号"/>
    </div>
    客户名称：
    <div class="layui-inline" style="width: 220px">
        <!--<input class="layui-input"  id="customerNameSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入客户名称"/>-->
        <select id="customerNameSearchSaleOrder" style="width: 200px;height: 25px">
            <option value="">请选择客户名称</option>
            <option th:each="purchaserName:${purchaserNameList}" th:value="${purchaserName}" th:text="${purchaserName}"></option>
        </select>
    </div>
    工程名称：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="projectNameSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入工程名称"/>
    </div>
    产品名称：
    <div class="layui-inline" style="width: 210px">
        <!--<input class="layui-input"  id="productNameOrderSearchSaleOrder" autocomplete="off" style="width: 190px;height: 25px" placeholder="请输入产品名称"/>-->
        <select id="productNameOrderSearchSaleOrder" style="width: 190px;height: 25px">
            <option value="">请选择产品名称</option>
            <option th:each="goodsNameP1:${goodsNameP}" th:value="${goodsNameP1.dataname}" th:text="${goodsNameP1.dataname}"></option>
        </select>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button><br/>
    产品规格：
    <div class="layui-inline" style="width: 220px">
        <!--<input class="layui-input"  id="productSpecificationsOrderSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入产品规格"/>-->
        <select id="productSpecificationsOrderSearchSaleOrder" style="width: 200px;height: 25px">
            <option value="">请选择产品规格</option>
            <option th:each="specificationsP1:${specificationsP}" th:value="${specificationsP1.dataname}" th:text="${specificationsP1.dataname}"></option>
        </select>
    </div>
    <div class="layui-inline" style="margin-left: -15px">操作员名称：</div>
    <div class="layui-inline" style="width: 220px;">
        <input class="layui-input"  id="operatorSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入操作员名称"/>
    </div>
    起始日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="startDateSearchSaleOrder" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="endDateSearchSaleOrder" autocomplete="off" style="width: 190px;height: 25px" placeholder="请选择截止日期"/>
    </div>

</div>
<script type="text/html" id="toolbarDemoSaleData">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addSaleData" >添加</button>
        <button class="layui-btn layui-btn-sm" lay-event="deleteSaleData" >删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="updateSaleData" >修改</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="update" id="update" >修改</button>-->
        <button class="layui-btn layui-btn-sm" lay-event="printSale" id="printSale" >打印订单</button>
        <button class="layui-btn layui-btn-sm" lay-event="printBarCodeS" >打印条形码</button>

    </div>
</script>
<table class="layui-table" lay-data="{url:'/order/querySaleOrder', page:true, id:'idTestSaleData',toolbar:'#toolbarDemoSaleData',defaultToolbar:['filter', 'print','exports'] }" lay-filter="demoSaleData">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}" ></th>
        <th lay-data="{field:'saleNum', width:180}" >销售单号</th>
        <th lay-data="{field:'customerName', width:150}" >客户名称</th>
        <th lay-data="{field:'date',width:150}" >订单日期</th>
        <th lay-data="{field:'projectName',width:150}" >工程名称</th>
        <th lay-data="{field:'endDate',width:150}" >需求日期</th>
        <th lay-data="{field:'productNameOrder',width:150}" >产品名称</th>
        <th lay-data="{field:'productSpecificationsOrder',width:150}" >产品规格</th>
        <th lay-data="{field:'customerPressure',width:150}" >使用压力</th>
        <th lay-data="{field:'customerNums',width:70}" >数量</th>
        <th lay-data="{field:'address',width:150}" >收货地址</th>
        <th lay-data="{field:'receiver',width:150}" >收货人</th>
        <th lay-data="{field:'telPhone',width:150}" >联系电话</th>
 <!--       <th lay-data="{field:'logisticsInformation',width:150}" >物流信息</th>-->
        <th lay-data="{field:'operator',width:150}">操作人</th>
        <th lay-data="{field:'operatorTime',width:180}" >操作时间</th>
        <th lay-data="{field:'kaiPiaoDate',width:180}" >开票时间</th>
        <th lay-data="{field:'shouKuanDate',width:180}" >收款时间</th>
        <th lay-data="{field:'status',width:150}" >订单状态</th>
        <th lay-data="{field:'remarks',width:180}" >备注</th>
    </tr>
    </thead>
</table>

<script th:src="@{/adminlte/layui/layui.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demoSaleData)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demoSaleData)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                /*layer.alert('编辑行：<br/>'+ JSON.stringify(data))*/

            }
        });
        //监听头工具栏事件
        table.on('toolbar(demoSaleData)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data//获取选中的数据
                ,deList=[1];
            data.forEach(function (n,i) {
                deList.push(n.id)
            });
            deList.push(2);
            switch(obj.event){
                case 'addSaleData':
                    layer.open({
                        type:2,
                        title:'添加',
                        area: ['1050px', '505px'],
                        content: '/order/sale',
                        end:function(){
                            table.reload('idTestSaleData');
                        }
                    });
                    break;
                case 'printSale':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时打印一个');
                    } else {
                        var id =checkStatus.data[0].id;
                        layer.open({
                            type:2,
                            title:'打印',
                            area: ['800px', '320px'],
                            content: '/order/printSaleOrder?id='+id,
                            end:function(){
                                table.reload('idTestSaleData');
                            }
                        });

                    }
                    break;
                case 'printBarCodeS':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时打印一个');
                    } else {
                        var id =checkStatus.data[0].id;
                        var productNum =checkStatus.data[0].saleNum;
                        layer.confirm('确定？',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/order/printBarCode" ,//url
                                data: {productNum:productNum},
                                success: function (result) {
                                    if (result.success>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }else{
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });

                    }
                    break;
                case 'updateSaleData':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        var id =checkStatus.data[0].id;
                        layer.confirm('确定？',{btn: ['确定', '取消'], title: "提示"},function(index){
                            layer.open({
                                type:2,
                                title:'修改',
                                area: ['1050px', '505px'],
                                content: '/order/modify?id='+id,
                                end:function(){
                                    table.reload('idTestSaleData');
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
                case 'deleteSaleData':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定删除',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/order/deleteSaleOrder" ,//url
                                data: {deList:JSON.stringify(deList)},
                                success: function (result) {
                                    if (result.success>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestSaleData')
                                    }else{
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                }/*,
                                error : function() {
                                    alert("异常！");
                                }*/
                            });
                            layer.close(index);
                        });
                    }
                    break;
            }
        });
        var $ = layui.$, active = {
            /*     getCheckData: function(){ //获取选中数据
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.alert(JSON.stringify(data));
                 }
                 ,getCheckLength: function(){ //获取选中数目
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.msg('选中了：'+ data.length + ' 个');
                 }
                 ,isAll: function(){ //验证是否全选
                     var checkStatus = table.checkStatus('idTest');
                     layer.msg(checkStatus.isAll ? '全选': '未全选')
                 }
                 ,*/
            reload:function () {
                var saleNum = $("#saleNumSearchSaleOrder").val();
                var customerName = $("#customerNameSearchSaleOrder").val();
                var projectName = $("#projectNameSearchSaleOrder").val();
                var productNameOrder = $("#productNameOrderSearchSaleOrder").val();
                var productSpecificationsOrder = $("#productSpecificationsOrderSearchSaleOrder").val();
                var operator = $("#operatorSearchSaleOrder").val();
                var startDate = $("#startDateSearchSaleOrder").val();
                var endDate = $("#endDateSearchSaleOrder").val();
                table.reload('idTestSaleData',{
                    url:'/order/searchSaleOrder',
                    where:{saleNum:saleNum,customerName:customerName,projectName:projectName,productNameOrder:productNameOrder,productSpecificationsOrder:productSpecificationsOrder,operator:operator,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }
        };

        $('.demoTableSaleOrder .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startDateSearchSaleOrder' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDateSearchSaleOrder' //指定元素
            ,type: 'datetime'
        });
    });
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>